package com.qingke.note.command;

import java.util.HashMap;
import java.util.Map;

import com.qingke.note.App;
import com.qingke.note.command_impl.*;
import com.qingke.note.pojo.User;

public class CommandFactory {
	private static Map<CommandCode, Class<? extends Command>> commandMap = new HashMap<CommandCode, Class<? extends Command>>();
	static{
		commandMap.put(CommandCode.LOGIN, LoginCommand.class);
		commandMap.put(CommandCode.SIGNUP, SignupCommand.class);
		commandMap.put(CommandCode.DELETE, DeleteCommand.class);
		commandMap.put(CommandCode.EXIT, ExitCommand.class);
		commandMap.put(CommandCode.LOGOUT, LogoutCommand.class);
		commandMap.put(CommandCode.HELP, HelpCommand.class);
		commandMap.put(CommandCode.NEW, NewCommand.class);
		commandMap.put(CommandCode.LIST, ListCommand.class);
		commandMap.put(CommandCode.UPDATE, UpdateCommand.class);
	}
	
	public Command buildCommand(CommandCode commandCode){
		User currentUser = App.getInstance().getCurrentUser();
		try {
			Class<? extends Command> cmdClass = commandMap.get(commandCode);
			return cmdClass.getConstructor(User.class).newInstance(currentUser);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;	
	}


}
